package com.tanhua.model.vo;


import com.alibaba.fastjson.JSON;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.testpaper.SoulReport;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class SoulReportVo implements Serializable {

    private String conclusion; // 鉴定结果
    private String cover; // 图片
    private List<SoulDimensionsVo> dimensions; // 维度
    private List<SoulSimilarVo> similarYou;  // 用户信息

    public static SoulReportVo init(SoulReport report, List<UserInfo> list) {
        SoulReportVo vo = new SoulReportVo();
        BeanUtils.copyProperties(report, vo);
        List<SoulDimensionsVo> dimensions = JSON.parseArray(report.getDimensions(),
                SoulDimensionsVo.class);
        vo.setDimensions(dimensions);
        vo.setConclusion(report.getTitle() + ":" + report.getContent());
        List<SoulSimilarVo> toList = new ArrayList<>();
        for (UserInfo userInfo : list) {
            toList.add(SoulSimilarVo.init(userInfo));
        }
        vo.setSimilarYou(toList);
        return vo;
    }
}
